﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public class ProductDAO : BaseService
    {
        public ProductDAO() { }
        public int GetMaxId()
        {
            string hql = "from Product order by Id desc";
            try
            {
                Product prod = FindList<Product>(hql, null, 0, 1).First();
                return prod.Id + 1;
            }
            catch (Exception)
            {

                return 1;
            }
        }
        public IList<Product> GetListByPager(int typeid,int state,string styleid, int page, int pagesize)
        {
            string hql = " from Product where 1=1";
            if (typeid !=0)
            {
                hql += " and ProductType=" + typeid;
            }
            if (state != -1)
            {
                hql += " and IsPub =" + state;
            }
            if (styleid != "0")
            {
                hql += " and StyleIds like '%" + styleid + "%'";
            }
            hql += " order by SortId desc";
            return FindList<Product>(hql, null, (page - 1) * pagesize, pagesize);
        }
        public int GetListByPager(int typeid, int state, string styleid)
        {
            string hql = "select count(*) from Product where 1=1";
            if (typeid != 0)
            {
                hql += " and ProductType=" + typeid;
            }
            if (state != -1)
            {
                hql += " and IsPub =" + state;
            }
            if (styleid != "0")
            {
                hql += " and StyleIds like '%" + styleid + "%'";
            }
            
            return Convert.ToInt32(GetValue(hql));
        }
    }
}
